﻿
using Microsoft.AspNetCore.Http;
using System.Threading.Tasks;

namespace GoodDotNet.App.filter
{
    public class CorsMiddleware
    {
        private readonly RequestDelegate _next;

        public CorsMiddleware(RequestDelegate next)
        {
            _next = next;
        }

        public async Task Invoke(HttpContext context)
        {
            Console.WriteLine("origin:{0}", context.Request.Headers["Origin"]);
            context.Response.Headers.Add("Access-Control-Allow-Origin", "http://localhost:8000");
            context.Response.Headers.Add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
            context.Response.Headers.Add("Access-Control-Allow-Headers", "Content-Type, Authorization");

            await _next(context);
        }
    }

}
